package com.woniu.cms.finance.core.controller;


import com.woniu.cms.finance.core.entity.FinanceAccounting;
import com.woniu.cms.finance.core.service.IFinanceAccountingService;
import com.woniu.common.api.Result;
import com.woniu.common.api.status.Impl.BusinessCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 项目列帐总表 前端控制器
 * </p>
 *
 * @author kiron
 * @since 2022-09-19
 */
@RestController
@RequestMapping("/finance-accounting")
@Api(tags = "项目列帐")
public class FinanceAccountingController {
    @Autowired
    private IFinanceAccountingService iFinanceAccountingService;

    @GetMapping("list")
    @ApiOperation("获取项目的财务信息")
    public Result getList(){
        Result r =iFinanceAccountingService.getList();
        return r;
    }

    @PostMapping("insert")
    @ApiOperation("新增列帐数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "financeAccounting",value = "保存的列帐单集合")
    })
    public Result addAccounting(@RequestBody List<FinanceAccounting> financeAccounting){
       Result result = iFinanceAccountingService.addAccounting(financeAccounting);
       return result;
    }


    @PutMapping("updateStatus")
    @ApiOperation("提交审批单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "financeAccountings",value = "需要提交的列账单")
    })
    public Result updateAccounting(@RequestBody List<FinanceAccounting> financeAccountings){
         financeAccountings.forEach(e->e.setAccountingStatus(1));
        boolean b = iFinanceAccountingService.updateBatchById(financeAccountings);
        if(!b){
            return Result.error("提交失败，请检查后重试");
        }
        return Result.ok("提交成功");
    }

    @DeleteMapping("deleteAccounting")
    @ApiOperation("删除未提交列帐")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "financeAccountings",value = "需要删除的列帐数据")
    })
    public Result deleteAccounting(@RequestBody List<FinanceAccounting> financeAccountings){
       Result result= iFinanceAccountingService.deleteAccounting(financeAccountings);
       return result;
    }

    @GetMapping("all")
    @ApiOperation("所有列帐查询")
    public Result getAll(Integer currentPage, Integer pageSize) {
        Result result = iFinanceAccountingService.getAll(currentPage, pageSize);
        return result;
    }
}

